<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //10. 九九乘法表
        for (let i = 1; i < 10; i++) {
            let str = '';
            for (let k = 1; k < i + 1; k++) {
                str = str + (k + "*" + i + "=" + i * k) + " ";
            }
            console.log(str);
        }

        // 11.while 循环完成1-100的求和
        let i = 1;
        let j = 0;
        while (i < 101) {
            j = j + i;//j+=i
            i++;
        }
        console.log(j);


        // 12.do-while 循环完成 1-100 的求和
        let num = 1;
        let num1 = 0;
        do {
            num1 = num1 + num;
            num++;
        } while (num < 101)
        console.log(num1);



        // 13. [2, 6, 6, 1, 77, 52, 25, 7 ,7]
        //1. 数组的最大值
        let arr = [2, 6, 1, 77, 52, 25, 7];
        let arr11 = [];
        //假设第一个是最大值
        let max = arr[0];
        for (let i = 1; i < arr.length; i++) {
            //console.log(arr[i]);//遍历一遍数组
            //依次比较 ,如果元素比较大，则给max重新赋值
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        console.log("数组的最大值是：" + max);

        // 数组的求和，平均数
        let sum = 0;
        for (let i = 0; i < arr.length; i++) {
            // console.log(arr[i]);//遍历输出
            sum = sum + i;
        }
        console.log('数组的和是' + sum);
        console.log('数组的平均数是' + sum / arr.length);

        // 筛选数组中大于 10 的元素放入新的数组
        let arr1 = [];
        for (let itme of arr) {
            //console.log(itme);  遍历一遍
            if (itme >= 10) {
                arr1[arr1.length] = itme;

            }
        }
        console.log(arr1);


        //  翻转元素，放入新的数组
        for (let i = arr.length - 1; i >= 0; i--) {//i 是索引号index

            // console.log(index, arr[index]); 倒遍历了一遍
            arr1[arr1.length] = arr[i]; //空数组的长度等于一个索引号遍历的
        }
        console.log(arr1);


        //数组的去重,形成新的数组

        for (let i = 0; i < arr.length; i++) {
            console.log(arr[i]); // 依次拿到老数组中的元素
            // 判断新数组是否有该元素
            let flag = false; // 默认不存在
            for (let item of arr1) {
                if (arr[i] == item) {
                    console.log('该元素已存在');
                    // flag = true;
                }
            }


            // 添加元素(新数组中不存在)
            if (!flag) {
                arr11[arr11.length] = arr[i];
            }
        }
        console.log(arr11);


        //数组的排序
        let arr6 = [2, 6, 52, 10, 77, 25, 62, 7];
        console.log(arr6);
        function sort(arr) {
            for (let j = 0; j < arr.length - 1; j++) {
                for (let i = 0; i < arr.length - 1 - j; i++) {
                    if (arr[i] > arr[i + 1]) {
                        let temp = arr[i];
                        arr[i] = arr[i + 1];
                        arr[i + 1] = temp;
                    }
                }

            }
        }
        sort(arr);

        console.log(arr);

    </script>
</body>

</html>